/**
 * Created by dh.huang on 2016/9/13.
 */
angular.module('inspinia')
  .controller('financeCtrl',['$scope','values',function ($scope,values) {
    var myChart = echarts.init(document.getElementById('main'));
    var myCahrtActual = echarts.init(document.getElementById('actual'));
    var myChartPlan = echarts.init(document.getElementById('plan'));

    // 指定图表的配置项和数据
    var option = {
      title: {
        text: '本周与上周对比(单位:万元)'
      },
      tooltip: {},
      legend: {
        data:['上周','本周']
      },
      xAxis: {
        data: ["星期一","星期二","星期三","星期四","星期五","星期六","星期天"]
      },
      yAxis: {},
      series: [{
        name: '上周',
        type: 'line',
        data: [50, 40, 36, 47, 38, 24,45]
      },{
        name: '本周',
        type: 'bar',
        data: [9, 18, 30, 20, 15, 28,40]
      }]
    };



    // 指定图表的配置项和数据
    var actualOption = {
      title: {
        text: '上周实际与计划对比图'
      },
      tooltip: {},
      legend: {
        data:['计划','实际']
      },
      xAxis: {
        data: ["星期一","星期二","星期三","星期四","星期五","星期六","星期天"]
      },
      yAxis: {},
      series: [{
        name: '计划',
        type: 'line',
        data: [5, 20, 36, 10, 10, 20,45]
      },{
        name: '实际',
        type: 'bar',
        data: [9, 18, 30, 20, 15, 28,40]
      }]
    };



    // 指定图表的配置项和数据
    var planOption = {
      title: {
        text: '本周实际与计划对比图'
      },
      tooltip: {},
      legend: {
        data:['计划','实际']
      },
      xAxis: {
        data: ["星期一","星期二","星期三","星期四","星期五","星期六","星期天"]
      },
      yAxis: {},
      series: [{
        name: '计划',
        type: 'line',
        data: [5, 20, 36, 10, 10, 20,45]
      },{
        name: '实际',
        type: 'bar',
        data: [9, 18, 30]
      }]
    };







    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
    myCahrtActual.setOption(actualOption);
    myChartPlan.setOption(planOption);



    /**
     * dashboardFlotTwo - simple controller for data
     * for Flot chart in Dashboard view
     */


    var data1 = [
      [gd(2012, 1, 1), 7],
      [gd(2012, 1, 2), 6],
      [gd(2012, 1, 3), 4],
      [gd(2012, 1, 4), 8],
      [gd(2012, 1, 5), 9],
      [gd(2012, 1, 6), 7],
      [gd(2012, 1, 7), 5],
      [gd(2012, 1, 8), 4],
      [gd(2012, 1, 9), 7],
      [gd(2012, 1, 10), 8],
      [gd(2012, 1, 11), 9],
      [gd(2012, 1, 12), 6],
      [gd(2012, 1, 13), 4],
      [gd(2012, 1, 14), 5],
      [gd(2012, 1, 15), 11],
      [gd(2012, 1, 16), 8],
      [gd(2012, 1, 17), 8],
      [gd(2012, 1, 18), 11],
      [gd(2012, 1, 19), 11],
      [gd(2012, 1, 20), 6],
      [gd(2012, 1, 21), 6],
      [gd(2012, 1, 22), 8],
      [gd(2012, 1, 23), 11],
      [gd(2012, 1, 24), 13],
      [gd(2012, 1, 25), 7],
      [gd(2012, 1, 26), 9],
      [gd(2012, 1, 27), 9],
      [gd(2012, 1, 28), 8],
      [gd(2012, 1, 29), 5],
      [gd(2012, 1, 30), 8],
      [gd(2012, 1, 31), 25]
    ];

    var data2 = [
      [gd(2012, 1, 1), 800],
      [gd(2012, 1, 2), 500],
      [gd(2012, 1, 3), 600],
      [gd(2012, 1, 4), 700],
      [gd(2012, 1, 5), 500],
      [gd(2012, 1, 6), 456],
      [gd(2012, 1, 7), 800],
      [gd(2012, 1, 8), 589],
      [gd(2012, 1, 9), 467],
      [gd(2012, 1, 10), 876],
      [gd(2012, 1, 11), 689],
      [gd(2012, 1, 12), 700],
      [gd(2012, 1, 13), 500],
      [gd(2012, 1, 14), 600],
      [gd(2012, 1, 15), 700],
      [gd(2012, 1, 16), 786],
      [gd(2012, 1, 17), 345],
      [gd(2012, 1, 18), 888],
      [gd(2012, 1, 19), 888],
      [gd(2012, 1, 20), 888],
      [gd(2012, 1, 21), 987],
      [gd(2012, 1, 22), 444],
      [gd(2012, 1, 23), 999],
      [gd(2012, 1, 24), 567],
      [gd(2012, 1, 25), 786],
      [gd(2012, 1, 26), 666],
      [gd(2012, 1, 27), 888],
      [gd(2012, 1, 28), 900],
      [gd(2012, 1, 29), 178],
      [gd(2012, 1, 30), 555],
      [gd(2012, 1, 31), 993]
    ];


    var dataset = [
      {
        label: "Number of orders",
        grow:{stepMode:"linear"},
        data: data2,
        color: "#1ab394",
        bars: {
          show: true,
          align: "center",
          barWidth: 24 * 60 * 60 * 600,
          lineWidth: 0
        }

      },
      {
        label: "Payments",
        grow:{stepMode:"linear"},
        data: data1,
        yaxis: 2,
        color: "#1C84C6",
        lines: {
          lineWidth: 1,
          show: true,
          fill: true,
          fillColor: {
            colors: [
              {
                opacity: 0.2
              },
              {
                opacity: 0.2
              }
            ]
          }
        }
      }
    ];


    var options = {
      grid: {
        hoverable: true,
        clickable: true,
        tickColor: "#d5d5d5",
        borderWidth: 0,
        color: '#d5d5d5'
      },
      colors: ["#1ab394", "#464f88"],
      tooltip: true,
      xaxis: {
        mode: "time",
        tickSize: [3, "day"],
        tickLength: 0,
        axisLabel: "Date",
        axisLabelUseCanvas: true,
        axisLabelFontSizePixels: 12,
        axisLabelFontFamily: 'Arial',
        axisLabelPadding: 10,
        color: "#d5d5d5"
      },
      yaxes: [
        {
          position: "left",
          max: 1070,
          color: "#d5d5d5",
          axisLabelUseCanvas: true,
          axisLabelFontSizePixels: 12,
          axisLabelFontFamily: 'Arial',
          axisLabelPadding: 3
        },
        {
          position: "right",
          color: "#d5d5d5",
          axisLabelUseCanvas: true,
          axisLabelFontSizePixels: 12,
          axisLabelFontFamily: ' Arial',
          axisLabelPadding: 67
        }
      ],
      legend: {
        noColumns: 1,
        labelBoxBorderColor: "#d5d5d5",
        position: "nw"
      }

    };

    function gd(year, month, day) {
      return new Date(year, month - 1, day).getTime();
    }

    /**
     * Definition of variables
     * Flot chart
     */
    this.flotData = dataset;
    this.flotOptions = options;



    /**
     * Options for Bar chart
     */
    this.barOptions = {
      scaleBeginAtZero : true,
      scaleShowGridLines : true,
      scaleGridLineColor : "rgba(0,0,0,.05)",
      scaleGridLineWidth : 1,
      barShowStroke : true,
      barStrokeWidth : 2,
      barValueSpacing : 5,
      barDatasetSpacing : 1
    };

    /**
     * Data for Bar chart
     */
    this.barData = {
      labels: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"],
      datasets: [
        {
          label: "My First dataset",
          fillColor: "rgba(220,0,220,0.5)",
          strokeColor: "rgba(220,0,220,0.8)",
          highlightFill: "rgba(220,0,220,0.75)",
          highlightStroke: "rgba(220,0,220,1)",
          data: [81, 45, 70, 34, 67, 23, 67]
        },

        {
          label: "My First dataset",
          fillColor: "rgba(220,220,0,0.5)",
          strokeColor: "rgba(220,220,0,0.8)",
          highlightFill: "rgba(220,220,0,0.75)",
          highlightStroke: "rgba(220,220,0,1)",
          data: [23, 65, 49, 90, 34, 80, 45]
        },


        {
          label: "My First dataset",
          fillColor: "rgba(220,220,220,0.5)",
          strokeColor: "rgba(220,220,220,0.8)",
          highlightFill: "rgba(220,220,220,0.75)",
          highlightStroke: "rgba(220,220,220,1)",
          data: [65, 59, 80, 81, 56, 55, 40]
        },


        {
          label: "My Second dataset",
          fillColor: "rgba(26,179,148,0.5)",
          strokeColor: "rgba(26,179,148,0.8)",
          highlightFill: "rgba(26,179,148,0.75)",
          highlightStroke: "rgba(26,179,148,1)",
          data: [28, 48, 40, 19, 86, 27, 90]
        }
      ]
    };

    $scope.statistics = [
      {
        id:'001',
        text:'缴费',
        name:'plan',
        count:'100万元',
      },
      {
        id:'002',
        text:'退费',
        name:'finished',
        count:'30万元',
      },
      {
        id:'003',
        text:'总计',
        name:'finished',
        count:'70万元',
      }
    ];
    $scope.parts= [
      {
        id: "101",
        name: "lung",
        txt: "肺癌",
        count:'14',
        contrast:'45%'
      },
      {
        id: "102",
        name: "breast",
        txt: "乳腺癌",
        count:'8',
        contrast:'24%'
      },
      {
        id: "103",
        name: "Cervical",
        txt: "宫颈癌",
        count:'13',
        contrast:'18%'
      },
      {
        id: "104",
        name: "rectum",
        txt: "直肠癌",
        count:'22',
        contrast:'78%'
      },
      {
        id: "105",
        name: "liver",
        txt: "肝 癌",
        count:'19',
        contrast:'12%'
      },
      {
        id: "106",
        name: "stomach",
        txt: "胃癌",
        count:'37',
        contrast:'36%'
      }
    ];
  }] );
